package com.rxyb.upms.service.logic;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rxyb.core.constants.DbConstants;
import com.rxyb.upms.db.bean.SysRole;
import com.rxyb.upms.db.dao.SysRoleMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

/**
 * @author YJH
 * @version 1.0
 * @description 权限管理
 * @date 2020/6/6  13:45
 */
@Component
@Slf4j
public class SysRoleLogic {

    private final SysRoleMapper sysRoleMapper;


    public SysRoleLogic(SysRoleMapper sysRoleMapper) {
        this.sysRoleMapper = sysRoleMapper;
    }


    /**
     * 根据roleId 查询用户信息
     *
     * @param roleId 查询用户信息
     * @return
     */
    public Optional<SysRole> findUserNameRole(Long roleId) {
        SysRole sysRole = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().lambda().eq(SysRole::getId, roleId).eq(SysRole::getRowStatus, DbConstants.ROW_STATE_VALID));
        if (null == sysRole) {
            log.warn("根据权限编号[{}]未查询到权限信息", roleId);
            return Optional.empty();
        }
        log.debug("根据权限编号[{}]查询到权限信息[{}]", roleId, JSONUtil.toJsonStr(sysRole));
        return Optional.of(sysRole);
    }
}
